$(document).on('click', '.FQA-list .FQA-t', function () {
	$(this).parents("ul").find(".FQA-c").hide();
	$(this).parents("li").find(".FQA-c").show();
});

var base_url = "http://zhuan.wenlongli.com";
var errSell = {};
var _true = ['有','是','已开基本户'];
var _false = ['无','否','未开基本户'];
var prefix = 'my_';
$(function () {
    /*-----------------input 添加说明信息-------------------*/
    addInformation();
    /*--------------是编辑时--------------------*/
    isEdit();
    /*---------使用原来样式--------------*/
	compatibilityStyle();
	/*--------------添加事件--------------哥们儿呀，你走吧，我干活里呀...*/
    addEvent();

    /*-----------------------验证对象-----------------------*/
    var _tipsMessage = {
        "type" : {
            rule: function(_this){
                var name = _this.attr('name');
                var val = $("input[name='"+name+"']:checked").val();
                if (val == undefined) {
                    return -1;
                }

                return 2;
            },
            prompt : "<i></i>请选择转让公司类型",
            err:"<i></i>请选择转让公司类型",
            success :"<i></i>"
        },
        "company" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }
                if (val.length > 20) {
                    return -1;
                }
                return 2;
            },
            prompt : "<i></i>请填写公司名称",
            err:"<i></i>请填写正确的公司名称",
            success :"<i></i>"
        },
        "register_num" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }
                if (val.length < 5) {
                    return -1;
                }
                return 2;
            },
            prompt : "<i></i>请填写社会信用代码",
            err:"<i></i>请填写正确的社会信用代码",
            success :"<i></i>"
        },
        "establish_at" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }

                return 2;
            },
            prompt : "<i></i>选择公司成立日期，如：2018-02-06",
            err:"<i></i>选择公司成立日期，如：2018-02-06",
            success :"<i></i>"
        },
        "register_capital" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }

                return 2;
            },
            prompt : "<i></i>请填写注册资本",
            err:"<i></i>请填写正确的注册资本",
            success :"<i></i>"
        },
        "is_aptitude": {
            rule: function(_this){
                var name = _this.attr('name');
                var val = $("input[name='"+name+"']:checked").val();
                if (val == undefined) {
                    return -1;
                }

                if(val == '有'){
                    var rBox= _this.parents('p').find('.rBox');
                    if(rBox == 'undefined' || rBox.length == 0){
                        return -1;
                    }
                    var tVal = rBox.find('textarea').val();
                    if(tVal.length <= 5){
                        return -1;
                    }
                }

                return 2;
            },
            prompt : "<i></i>请填写资质描述",
            err:"<i></i>请正确填写资质描述",
            success :"<i></i>"
        },
        "is_trademark": {
            rule: function(_this){
                var name = _this.attr('name');
                var val = $("input[name='"+name+"']:checked").val();
                if (val == 'undefined') {
                    return -1;
                }

                if(val == '有'){
                    var rBox= _this.parents('p').find('.rBox');
                    if(rBox == 'undefined' || rBox.length == 0){
                        return -1;
                    }
                    var tVal = rBox.find('textarea').val();
                    if(tVal.length <= 5){
                        return -1;
                    }
                }

                return 2;
            },
            prompt : "<i></i>请填写商标描述",
            err:"<i></i>请正确填写商标描述",
            success :"<i></i>"
        },
        "is_onlinestore": {
            rule: function(_this){
                var name = _this.attr('name');
                var val = $("input[name='"+name+"']:checked").val();
                if (val == 'undefined') {
                    return -1;
                }

                if(val == '有'){
                    var rBox= _this.parents('p').find('.rBox');
                    if(rBox == 'undefined' || rBox.length == 0){
                        return -1;
                    }
                    var tVal = rBox.find('textarea').val();
                    if(tVal.length <= 5){
                        return -1;
                    }
                }

                return 2;
            },
            prompt : "<i></i>请填写网络资产描述",
            err:"<i></i>请正确填写网络资产描述",
            success :"<i></i>"
        },
        "paid_capital" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }

                return 2;
            },
            prompt : "<i></i>请填写实缴资本",
            err:"<i></i>请填写正确的实缴资本",
            success :"<i></i>"
        },
        "business_scope" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }

                return 2;
            },
            prompt : "<i></i>请填写经营范围",
            err:"<i></i>请填写正确的经营范围",
            success :"<i></i>"
        },
        "price" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }

                return 2;
            },
            prompt : "<i></i>请填写转让价格",
            err:"<i></i>请填写正确的转让价格",
            success :"<i></i>"
        },
        "phone" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }

                return 2;
            },
            prompt : "<i></i>请填写手机号",
            err:"<i></i>请填写正确的手机号",
            success :"<i></i>"
        },
        "linkman" : {
            rule: function(_this){
                var val = _this.val();
                if (val == '') {
                    return 1;
                }

                return 2;
            },
            prompt : "<i></i>请填写联系人",
            err:"<i></i>请填写正确的联系人",
            success :"<i></i>"
        }
    }
    /*-------------------input 输入验证 -------------------------------*/
    $("input[type=text]").on('focus blur input',function(){
        /*
        *检查满不满足自已的规则
        *
        * */
        $(this).addClass("on");
        var _p = $(this).parents('p');
    	var name = $(this).attr('name');
    	var errType = 'prompt';
        if(name in _tipsMessage){
            var validation = _tipsMessage[name].rule( $(this) );

            if(validation == 1){ // 提示
				errType = 'prompt'
                errSell.name = _tipsMessage[name][errType];
			}
            if(validation == -1){ // 错误
                errType = 'err'
                errSell.name = _tipsMessage[name][errType];
            }
            if(validation == 2){ // 成功
                errType = 'success';
                $(this).removeClass("on");
            }

            var c = $("<span class='c'><span class='tips "+errType+"' style='display: inline;'>"+_tipsMessage[name][errType]+"</span></span>");
            var tips = c.find(".tips");

            _p.find('.c').remove();
            _p.append(c);
        }
    });

    /*-------------------提交表单-------------------*/
	$("#SaveSell2").on('click',function () {
		var errObj = {};
		$(".cont .Line input").each(function (k,v) {
			var name = $(v).attr('name');
            if(name in _tipsMessage){
                var validation = _tipsMessage[name].rule( $(v) );
                if(validation == 1){ // 提示
                    errObj[name] = _tipsMessage[name]['prompt'];
                    return false;
                }
                if(validation == -1){ // 错误
                    errObj[name] = _tipsMessage[name]['err'];
                    return false;
                }
                if(validation == 2){ // 成功
                	delete errObj.name;
                }
            }
        });
        var keys = Object.keys(errObj);
        if(keys.length > 0){
            layer.alert(errObj[keys[0]]);
		} else {
            if($('#protocol').is(':checked')) {
                // 提交表单
				/*var company = $("input[name='company']").val();
                console.log(company);
                $("#addcompany").append("<input type='hidden' name='title' value='"+company+"'/>")*/
                $("#addcompany").submit();
            } else {
                layer.alert('请阅读并同意《快转网转让协议》');
                return;
            }
		}

    });
});

// 当是编辑页面时
function isEdit() {
    if(typeof saff == 'undefined'){
        return;
    }
    var dataObj = {};
    $.each(saff,function (key, item) {
        var temp = key.split('__');
        var pName = temp[0];
        // var cName = temp[1];
        if(typeof dataObj[pName] == 'undefined'){
            dataObj[pName] = {};
        }

        dataObj[pName][key] = item;
    });

    var type_1 = ['is_aptitude','is_trademark','is_onlinestore'];
    var type_2 = ['is_licenseplate','is_patent'];
    var type_3 = ['tax_report'];

    $.each(dataObj,function (key,item) {
        var name = key;
        var target  = $("input[name='"+name+"']:checked");
        if( $.inArray(target.val(), _true) != -1){
            if( $.inArray(name, type_1) != -1 ){
                showOtherByEdit(name,item);
            }
            if( $.inArray(name, type_2) != -1 ){
                showRboxByEdit({
                    'name':name,
                    'selfAff':key,
                    'data':item
                });
            }
            if( $.inArray(name, type_3) != -1 ){
                showExtendRadio({
                    '_this': $("input[name='"+name+"']"),
                    'selfAff':key,
                    'data':item,
                    'action':'edit'
                });
            }
            if(name == 'bank_account'){
                showBankAccount({
                    '_this': $("input[name='"+name+"']"),
                    'selfAff':key,
                    'data':item,
                    'action':'edit'
                });
            }
        }

    });
}
function compatibilityStyle() {
    var p = $(".cont p");
    /*---------radio 全置为未选中状态--------------*/
    if(typeof saff == 'undefined'){
        p.children("input[type=radio]").prop('checked',false);
    }
    /*---------textarea 的label 垂直靠上--------------*/
    p.find('textarea').prev('label').css('vertical-align','top');
    /*---------添加Line--------------*/
    p.addClass('Line');

    /*---------添加*号等--------------*/
	var requireArr = [
		'type','company','register_num','register_capital','establish_at','business_scope','nativeplace','is_aptitude','is_trademark','is_onlinestore',
		'is_licenseplate','is_patent','tax_report','bank_account','price_type','phone','linkman'
	];
	var placeholder = {
        company: "请填写完整的公司名称",
        register_num: "请填写正确的社会信用代码",
        establish_at: "以执照上的成立日期为准",
        business_scope: "完整的经营范围更利于快速卖出，请与执照上的经营范围保持统一",
        other_content: "未尽信息或公司资产，可在此做详细描述"
	};

    $(".cont p").each(function (k,v) {
    	var input = $(v).find('input');
    	var select = $(v).find('select');
    	var textarea = $(v).find('textarea');
    	if(input.length){
            name = input.attr('name');
            input.attr('placeholder',placeholder[name]);
		}
        if(select.length){
            name = select.attr('name');
        }
        if(textarea.length){
            name = textarea.attr('name');
            textarea.attr('placeholder',placeholder[name]);
        }

        if($.inArray(name, requireArr) != -1){
            var label = $(v).children('label');
            var text = label.text();
            label.html("<span style='color: #ff5a00;font-size: 16px;font-weight: bold;margin-right: 5px;'>*</span>"+text);
		}
    });
}

function addInformation() {
	/*-----------------公司类型-----------------------*/
    var _p = $("input[name='type']").parents('p');
	var html = "<a class='mark' style='font-size: 14px;padding-left: 30px;color: red;'>" +
		"<i></i>如何区分空壳公司和实体公司..？" +
		"<div class='bz2' style='font-size: 12px; width: 320px; margin-right: 250px; height: 65px; margin-top: -125px;'>" +
		"空壳公司：只转让执照或含有资质、商标等无形资产的公司<br>" +
		"实体公司：必须连同产品、库存、设备、人员团队、经营产地等其中任何一项有形资产的公司" +
		"</div>" +
		"<span class='bz2i' style='margin-right: 535px;'><img src='https://www.51kuaizhuan.com/static/web/images/mark-cont-b.png'></span>" +
		"</a>";
    	_p.find(".mark").remove();
        _p.append(html);

    /*-----------------公司类型-----------------------*/
    var _p = $("input[name='paid_capital']").parents('p');
    var html =  "<a class='mark' style='font-size: 14px;color: red;'>"+
				"<i></i>什么是实缴资本？"+
				"<div class='bz2' style='height: 50px;margin-top: -115px;margin-right: 320px;'>经过银行验资，并出具验资报告的资金；对于未经过验资而注册的公司，实缴资本为0</div>"+
				"<span class='bz2i' style='margin-top: -52px;margin-right: 580px;'><img src='https://www.51kuaizhuan.com/static/web/images/mark-cont-b.png'></span>"+ "</a>";
    _p.find(".mark").remove();
    _p.append(html);
}

function addEvent() {
	$("#establish_at").on("click",function () {
        layui.laydate({istime: true, elem: this, festival: true, max: laydate.now()});
    });

    $(".cont").on('click',"input[type='radio']",function(){
        var name = $(this).attr('name');
        var val = $(this).val();
        var spans = $(this).parents('p').data('span');
        var extend = '';
        if(spans != 'undefined' || spans != ''){
            extend = '&extend='+spans;
        }
        var options = {
            'base_url':base_url,
            'name':name,
            'extend':extend,
        };
        /*---------------纳税类型-------------*/
        if(name == 'tax_report__tax_type'){
            var v = $(this).parents('p')
                            .siblings('.tax_report')
                            .find("input[name='tax_report__apply_invoice']:checked")
                            .data('val');
            if(v == '1'){
                showExtendOther($("input[name='tax_report__apply_invoice']"));
            }
        }
        /*---------------转让价格-------------*/
        if(name == 'price_type'){
            if(val == '一口价'){
                $(this).parents('p').append("<div style='margin-left: 30em;margin-top: -2.2em;' class='rBox'><input type='text' name='price_type__price'/>&nbsp;元</div>");
            } else {
                clearBox($(this));
            }
            return;
        }

        if($.inArray(val, _true) != -1){
            /*--------------是否有资质--------------*/
            if(name == 'is_aptitude'){ // 暂就这吧
                layerOpen(options);
            }

            /*---------------是否有商标-------------*/
            if(name == 'is_trademark'){ // 暂就这吧
                layerOpen(options);
            }
            /*---------------是否有网络资产-------------*/
            if(name == 'is_onlinestore'){ // 暂就这吧
                layerOpen(options);
            }

            /*---------------是否有车牌指标-------------*/
            if(name == 'is_licenseplate'){
                showRbox($(this));
            }
            /*---------------是否有车牌指标-------------*/
            if(name == 'is_patent'){
                showRbox($(this));
            }
            /*---------------是否有车牌指标-------------*/
            if(name == 'tax_report'){
                clearBox($(this));
                showExtendRadio({
                    '_this':$(this),
                    'action':'add'
                });
            }
            /*---------------是否申领过发票-------------*/
            if(name == 'tax_report__apply_invoice'){
                showExtendOther($(this));
            }
            /*---------------银行账户-------------*/
            if(name == 'bank_account'){
                clearBox($(this));
                showBankAccount({
                    _this: $(this),
                    action: 'add'
                });
            }
        } else {
            clearBox($(this));
        }
    });

    $(".cont p").on("click",".addBtn",function () {
        var p = $(this).parents('p');
        var name = p.find("input[type='radio']").attr('name');
        var spans = p.data('span');
        var extend = '';
        if(spans != undefined || spans != ''){
            extend = '&extend='+spans;
        }
        var options = {
            'base_url':base_url,
            'name':name,
            'extend':extend,
        };
        layerOpen(options);
    });
}

function layerOpen(op) {
    var url = op.base_url+'/plus/my_test.php?flag='+op.name+'&doget=top'+op.extend;
    layer.open({
        type: 2,
        title:'选择标签',
        area: ['35%', '500px'],
        shadeClose: true,
        shade: 0.8,
        content: url, 
        btn: ['取消', '确定'],
        btn2: function(index, layero){
            var iframe = $(layero).find("iframe")[0].contentWindow;
            var data = iframe.getMsg();
            var name = iframe.getName();
            var span = data.find('.msg span');

            showOther(name,span);
            layer.close(index);
        },
        cancel: function(){

        }
    });
}

//
function showOther(name, spans) {
    var selfInpName = 'is_'+name;
    var selfAff = selfInpName+'__'+name;
    var target = $("input[name='"+selfInpName+"']");
    var p = target.parents('p');
    p.data('span', '' );
    var checked = [];

    if(spans.length < 0){
        return false;
    }

    $(spans).each(function (key, item) {
        var eValue = $(item).data('evalue');
        checked.push(eValue);
        // 移除原来事件
        // ele.find('.del').off('doDel');
        // 添加新事件
        $(item).find('.del').on("click",function () {
            doDel( $(this));
        });
    });

    // 记录选择的值
    p.data('span', checked.join() );
    var sData = checked;
    // 提交的隐藏表单
    var submit_input = p.find('.submit_data');
    if(submit_input != undefined && submit_input.length){
        submit_input.val(sData.join('_'));
    } else {
        p.append("<input type='hidden' class='submit_data' name='"+selfAff+"_data' value='"+sData.join('_')+"'/>");
    }

    var rBox = $("<div class='rBox'></div>");
    var sBox = $("<div class='sBox'></div>");
    var dBox = $("<div class='dBox'></div>");
    // var bBox = $("<div class='bBox'></div>");
    var url = base_url+'/plus/my_test.php?flag='+name+'&doget=top';
    var btn = "<button type='button' data-url='"+url+"' class='addBtn selladd'>+ 添加</button>";
    var textarea = $("<textarea name='"+selfAff+"_desc' id='"+selfAff+"_desc'></textarea>");
        textarea.attr('placeholder', getTextareaPlaces(name));

    rBox.html('');

    sBox.append(spans);
    dBox.append(textarea);
    sBox.find('span:last').after(btn);
    // bBox.html(btn);
    rBox.append(sBox);
    rBox.find('.sBox').after(dBox);

    p.find('.rBox').remove();
    p.append(rBox);
}

function showOtherByEdit(name, data) {
    var _data,_desc;
    $.each(data,function (k,v) {
        if(k.indexOf('_data') != -1){
            _data = k;
        }
        if(k.indexOf('_desc') != -1){
            _desc = k;
        }
    });

    var spans = data[_data];
    var target = $("input[name='"+name+"']");
    var p = target.parents('p');
    p.data('span', '' );
    var checked = [];

    if(spans.length < 0){
        return false;
    }

    var sBox = $("<div class='sBox'></div>");
    $.each(spans,function (key, item) {
        var ele = $("<span id='"+key+"' data-evalue='"+key+"'>" +item+
                "<i class='del' style='display: inline-block;margin-left: 5px;color: #fff;font-size: 18px;cursor: pointer;vertical-align: bottom;margin-left: 5px;margin-right: -5px;font-style: normal;'>×</i>" +
                "</span>");
        checked.push(key);

        ele.find('.del').on("click",function () {
            doDel( $(this));
        });
        sBox.append(ele);
    });

    // 记录选择的值
    p.data('span', checked.join() );
    var sData = checked;
    // 提交的隐藏表单
    var submit_input = p.find('.submit_data');
    if(submit_input != undefined && submit_input.length){
        submit_input.val(sData.join('_'));
    } else {
        p.append("<input type='hidden' class='submit_data' name='"+_data+"' value='"+sData.join('_')+"'/>");
    }

    var rBox = $("<div class='rBox'></div>");
    var dBox = $("<div class='dBox'></div>");
    // var bBox = $("<div class='bBox'></div>");
    var url = base_url+'/plus/my_test.php?flag='+name+'&doget=top';
    var btn = "<button type='button' data-url='"+url+"' class='addBtn selladd'>+ 添加</button>";
    var textarea = $("<textarea name='"+_desc+"' id='"+_desc+"'>"+data[_desc]+"</textarea>");
    textarea.attr('placeholder', getTextareaPlaces(name));

    rBox.html('');

    dBox.append(textarea);
    sBox.find('span:last').after(btn);
    // bBox.html(btn);
    rBox.append(sBox);
    rBox.find('.sBox').after(dBox);
    p.find('.rBox').remove();
    p.append(rBox);
}



function doDel(_this) {
    // 把记录的data 值删除
    var _eValue = _this.parent().data('evalue').toString();
    var p = _this.parents('p');
    var data = p.data('span');
    var dataArr = data.split(',');
    var index = $.inArray(_eValue, dataArr);
    if(index == -1){ // 肯定能找到，，
        return false;
    }

    dataArr.splice(index,1);
    p.data('span', dataArr.join());

    // 如果全部删除，把radio 置为“无”
    if(dataArr.length <= 0){
        _this.parents('.rBox').siblings("input[type='radio'][value='无']").prop('checked',true);
        _this.parents('.rBox').remove();
    } else {
        // 把自己删除
        _this.parent().remove();
    }
    return true;
}

//点击无时清除box
function clearBox(_this) {
    var name = _this.attr('name');
    var nextRadio = $(_this).parents('p').nextAll('.'+name);
    if(nextRadio.length){
        nextRadio.remove();
    }else{
        _this.parents('p').data('span','');
        _this.siblings('.rBox').remove();
    }
}

// 显示右边textarea
function showRbox(_this) {
    var p = _this.parents('p');
    var rBox = $("<div class='rBox'></div>");
    var dBox = $("<div class='dBox'></div>");
    var name = _this.attr('name').split('_');
    var selfAff = _this.attr('name')+'__'+name[1]
    var textarea = $("<textarea name='"+selfAff+"_desc' id='"+selfAff+"_desc'></textarea>");
        textarea.attr('placeholder', getTextareaPlaces(name[1]));
    dBox.append(textarea);
    rBox.append(dBox);

    p.find('.rBox').remove();
    p.append(rBox);
}
function showRboxByEdit(options) {
    var values = Object.values(options.data);
    var _this = $("input[name='"+options.name+"']");
    var p = _this.parents('p');
    var rBox = $("<div class='rBox'></div>");
    var dBox = $("<div class='dBox'></div>");
    var textarea = $("<textarea name='"+options.selfAff+"' id='"+options.selfAff+"'>"+values[0]+"</textarea>");
    textarea.attr('placeholder', getTextareaPlaces(options.name));
    dBox.append(textarea);
    rBox.append(dBox);

    p.find('.rBox').remove();
    p.append(rBox);
}

//
function showExtendRadio(options) {
    var aciton = options.action;
    var name =options._this.attr('name');
    var p = options._this.parents('p');
    var ops = [
        {
            'pName': name,
            'name': name+'__tax_type',
            'type': 'radio',
            'text': '纳税类型',
            'data':[
                {value:1,sText:'小规模'},
                {value:2,sText:'一般纳税人'}
            ]
        },
        {
            'pName': name,
            'name': name+'__tax_returns',
            'type': 'radio',
            'text': '报税情况',
            'data':[
                {value:1,sText:'正常'},
                {value:2,sText:'非正常'}
            ]
        },
        {
            'pName': name,
            'name': name+'__apply_invoice',
            'type': 'radio',
            'text': '是否申领过发票',
            'data':[
                {value:1,sText:'是'},
                {value:2,sText:'否'}
            ]
        }
    ];
    $(ops).each(function (key, item) {
        //编辑判断
        if(options.action == 'edit'){
            $.each(options.data, function (k, v) {
                if(k == item.name) {
                    $(item.data).each(function (m,n) {
                        if(n.sText == v){
                            n.checked = true;
                        }
                    });
                }
            });
        }

        //生成p
        var newP = createP(item);
        if($('.'+name).length){
            $('.'+name).last().after(newP);
        } else {
            p.after(newP);
        }
    });
}

function showBankAccount(options) {
    var aciton = options.action;
    var name =options._this.attr('name');
    var p = options._this.parents('p');
    var ops = [
        {
            'pName': name,
            'name': name+'__bank_account_status',
            'type': 'radio',
            'text': '银行账户是否正常',
            'data':[
                {value:1,sText:'正常'},
                {value:2,sText:'不正常'}
            ]
        },
        {
            'pName': name,
            'name': name+'__bank_account_online',
            'type': 'radio',
            'text': '是否有网银',
            'data':[
                {value:1,sText:'有网银'},
                {value:2,sText:'无网银'}
            ]
        },
        {
            'pName': name,
            'name': name+'__bank_account_fwater',
            'type': 'textarea',
            'text': '银行流水情况',
            'data':[
                {value:1,sText:'如果你的银行流水频次多，流水额大请做简单描述，利于你的成交价。'}
            ]
        }
    ];
    $(ops).each(function (key, item) {
        //编辑判断
        if(options.action == 'edit'){
            $.each(options.data, function (k, v) {
                if(k == item.name) {
                    if(item.type == 'textarea') {
                        item.data[0].value = v;
                    }
                    if(item.type == 'radio'){
                        $(item.data).each(function (m,n) {
                            if(n.sText == v){
                                n.checked = true;
                            }
                        });
                    }
                }
            });
        }
        console.log(item);
        //生成p
        var newP = createP(item);
        if($('.'+name).length){
            $('.'+name).last().after(newP);
        } else {
            p.after(newP);
        }
    });
}

function showExtendOther(_this) {
    var p = _this.parents('p');

    var rBox = $("<div class='rBox'></div>");
    var dBox = $("<div class='dBox'></div>");
    var name = _this.attr('name');
    var taxType = p.siblings('.tax_report').find("input[name='tax_report__tax_type']:checked").data('val');
    dBox.append(createByInvoice('special','tax_report__tax_type'));
    if(taxType == 2){ // 一般纳税人
        dBox.append(createByInvoice('ordinary','tax_report__tax_type'));
    }

    rBox.append(dBox);

    p.find('.rBox').remove();
    p.append(rBox);
}

/*----------------------辅助函数----------------------*/
function createP(options) {
    var p = $("<p class='Line "+options.pName+"'>" +
        "<label><span style='color: #ff5a00;font-size: 16px;font-weight: bold;margin-right: 5px;'>*</span>"+options.text+"</label>" +
        "</p>");
        $(options.data).each(function (key,item) {
            var element = '';
            if(options.type == 'radio'){
                var checked = item.hasOwnProperty('checked') && item.checked ? 'checked': '';
                element = "<input type='radio' name='"+options.name+"' "+checked+" class='np' data-val='"+item.value+"' value='"+item.sText+"'> "+item.sText;
            }
            if(options.type == 'textarea'){
                element = "<textarea name='"+options.name+"' id='"+options.name+"' placeholder='"+item.sText+"' >"+item.value+"</textarea>";
                p.find('label').css('vertical-align','top')
            }
            p.append(element);

        });
    return p ;
}

function createSelect(params) {
    var s = $("<select name='"+params.name+"'></select>");
    var options = "<option value='-1'>请选择</option>";
    $.each(params.data,function (key, item) {
        var selected = '';
        if(item.id == params.selected){
            selected = 'selected';
        }
        options += "<option "+selected+" value='"+item.id+"'>"+item.text+"</option>";
    });
    s.html(options);
    return s ;
}

function createByInvoice(type, pName) {
    var div = $("<div style='margin-top: 0.8em;' class='"+type+"'></div>");
    var select;
    var flag = $("<span></span>");
    var dz = $("<span>——> 单张最高可开：</span>");
    var dz_end = $("<span>&nbsp;&nbsp;元版&nbsp;&nbsp;</span>");
    var num = $("<span>———> 单次最高可领</span>");
    var num_end = $("<span>份</span>");
    var input = $("<input style='width: auto !important;' type='text' name='"+pName+'__'+type+"_num'/>");

    var data = [
        {id:1,text:999},
        {id:2,text:9999},
        {id:3,text:99999},
        {id:4,text:999999},
    ];
    if(type == 'special'){
        flag.html('专用发票');
        select = createSelect({'data': data, 'name': pName+'__special_invoice', 'selected': 1});
    }

    if(type == 'ordinary'){
        flag.html('普通发票');
        select = createSelect({'data': data, 'name': pName+'__ordinary_invoice', 'selected': 4});
    }

    if(select == 'undefined'){
        throw new Error('select is undefined');
    }

    div.append(flag);
    div.append(dz);
    div.append(select);
    div.append(dz_end);
    div.append(num);
    div.append(input);
    div.append(num_end);

    return div;
}

function getTextareaPlaces(name) {
    var place = {
        'aptitude': '完整的呈现资质信息对公司的价值很重要，由于资质分类不全导致你选择其它资质时，务必在此做详细描述',
        'onlinestore': '为了更准确的呈现贵司网络资产价值，请务必在此做详细描述。',
        'trademark': '请具体描述公司商标详情',
        'licenseplate': '请具体描述公司车牌指标详情',
        'patent': '请具体描述公司专利／著作权',
        'report': '请具体描述fdsf权'
    };
    return place.hasOwnProperty(name) ? place[name] : '';
}

function checkRate(number) {
	var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/
	if (!re.test(number)) {
		return false;
	}
	return true;
}

